package cn.bdqn.mapper;

import cn.bdqn.pojo.SysUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SysUserMapperTester {
    @Resource
    SysUserMapper sysUserMapper;
//    @Test
//    public void testSelectList(){
//        List<SysUser> list=sysUserMapper.selectList(null);
//        for (SysUser sysUser : list) {
//            System.out.println(sysUser);
//        }
//    }
    @Test
    public void testUpdate(){
        SysUser sysUser=new SysUser();
        sysUser.setUsrId(18L);
        sysUser.setUsrName("lisi");
        sysUser.setUsrPassword("888888");
        sysUser.setUsrRoleId(2L);
        sysUser.setUsrFlag(0);
        int result = sysUserMapper.updateById(sysUser);
        if(result>0){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
    }
    @Test
    public void testDalete(){
        int result =sysUserMapper.deleteById(18L);
        if (result>0){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }
    }

    @Test
    public void testSelectById(){
        SysUser sysUser = sysUserMapper.selectById(2l);
        System.out.println(sysUser);
    }
    @Test
   public void testSelectList(){
       List<SysUser> sysUsers = sysUserMapper.selectList(null);
       for (SysUser sysUser : sysUsers) {
           System.out.println(sysUser);
       }
   }
   @Test
   public void testSelectPage(){
       //1 创建IPage分页对象,设置分页参数,1为当前页码，2为每页显示的条数
       Page<SysUser> page=new Page(1,2);
       sysUserMapper.selectPage(page,null);
       System.out.println("当前第几页："+page.getCurrent());
       System.out.println("每页显示多少条："+page.getSize());
       System.out.println("总共多少条记录："+page.getTotal());
       System.out.println("总共多少页："+page.getPages());
       System.out.println("每页显示的数据："+page.getRecords());
   }
   @Test
   public void testWrapperEq(){
       QueryWrapper qw=new QueryWrapper();
       qw.like("usr_name","h");
       List<SysUser> list = sysUserMapper.selectList(qw);
       for (SysUser sysUser : list) {
           System.out.println(sysUser);
       }
   }
   @Test
   public void testWrapperRange(){
       QueryWrapper qw=new QueryWrapper();
       qw.ge("usr_id",1);
       qw.le("usr_id",10);

       List<SysUser> list = sysUserMapper.selectList(qw);
       for (SysUser sysUser : list) {
           System.out.println(sysUser);
       }
   }

   @Test
    public void testWrapperSort() {
        QueryWrapper  qw=new QueryWrapper();
       qw.orderByDesc("usr_id");
        List<SysUser> list = sysUserMapper.selectList(qw);
        for (SysUser sysUser : list) {
            System.out.println(sysUser);
        }
    }
    @Test
    public void testWrapperConditions() {
        QueryWrapper  qw=new QueryWrapper();
        qw.eq("usr_name","hlliu");
        qw.eq("usr_password","pwd");
        SysUser sysUser = sysUserMapper.selectOne(qw);
        System.out.println(sysUser);
    }
}
